/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package com.esm.sm800.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.esm.sm800.R;
import com.esm.sm800.database.dbmodel.Member;
import com.esm.sm800.database.manager.MemberCenter;

import zuo.biao.library.base.BaseView;
import zuo.biao.library.model.Entry;

//用户
public class DemoView extends BaseView<Entry<Integer, String>> {
    private static final String TAG = "DemoView";

    public DemoView(Activity context, ViewGroup parent) {
        super(context, R.layout.member_view, parent);
    }

    public TextView tv_id;
    public TextView tv_name;
    public TextView tv_account;
    public TextView tv_jiaose;
    public TextView tv_remark;

    @Override
    public View createView() {
        tv_id = findView(R.id.tv_id);
        tv_name = findView(R.id.tv_name);
        tv_account = findView(R.id.tv_account);
        tv_jiaose = findView(R.id.tv_jiaose);
        tv_remark = findView(R.id.tv_remark);
        return super.createView();
    }


    @Override
    public void bindView(Entry<Integer, String> data_) {
        super.bindView(data_ != null ? data_ : new Entry<Integer, String>());
//        itemView.setBackgroundResource(selected ? R.drawable.alpha3 : R.drawable.white_to_alpha);
        int index = data.getKey();
        if (index < MemberCenter.getInstance().memberlist.size()) {
            Member m = MemberCenter.getInstance().memberlist.get(index);
            tv_id.setText("" + (index + 1));
            tv_name.setText(m.getName());
            tv_account.setText(m.getAccount());

            String[] TYPES = getResources().getStringArray(R.array.member_types);
            int type = m.getType();
            if (type >= 0 && type < TYPES.length) {
                tv_jiaose.setText(TYPES[type]);
            }
            tv_remark.setText(m.getRemark());
        }
    }

}
